package nz.jdbcwrapper;

import java.sql.SQLException;
import java.sql.ResultSetMetaData;

class WrapperResultSetMetaData implements ResultSetMetaData
{
  final ResultSetMetaData resultSetMetaData;
  final long id = Util.id();
  final String prefix;
  final Data data;

  WrapperResultSetMetaData(Data data,
                           String prefix,
                           ResultSetMetaData resultSetMetaData)
  {
    this.data = data;
    this.resultSetMetaData = resultSetMetaData;
    this.prefix = prefix + "[" + id + "]";
  }


  public int getColumnCount() throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getColumnCount()");
    try
    {
      int result = resultSetMetaData.getColumnCount();
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isAutoIncrement(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isAutoIncrement(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isAutoIncrement(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isCaseSensitive(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isCaseSensitive(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isCaseSensitive(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isSearchable(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isSearchable(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isSearchable(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isCurrency(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isCurrency(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isCurrency(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public int isNullable(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isNullable(" + column + ")");
    try
    {
      int result = resultSetMetaData.isNullable(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isSigned(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isSigned(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isSigned(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public int getColumnDisplaySize(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getColumnDisplaySize(" + column + ")");
    try
    {
      int result = resultSetMetaData.getColumnDisplaySize(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public String getColumnLabel(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getColumnLabel(" + column + ")");
    try
    {
      String result = resultSetMetaData.getColumnLabel(column);
      if (data.trace >= 5)
        Util.traceEnd(key, Util.toString(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public String getColumnName(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getColumnName(" + column + ")");
    try
    {
      String result = resultSetMetaData.getColumnName(column);
      if (data.trace >= 5)
        Util.traceEnd(key, Util.toString(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public String getSchemaName(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getSchemaName(" + column + ")");
    try
    {
      String result = resultSetMetaData.getSchemaName(column);
      if (data.trace >= 5)
        Util.traceEnd(key, Util.toString(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public int getPrecision(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getPrecision(" + column + ")");
    try
    {
      int result = resultSetMetaData.getPrecision(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public int getScale(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getScale(" + column + ")");
    try
    {
      int result = resultSetMetaData.getScale(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public String getTableName(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getTableName(" + column + ")");
    try
    {
      String result = resultSetMetaData.getTableName(column);
      if (data.trace >= 5)
        Util.traceEnd(key, Util.toString(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public String getCatalogName(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getCatalogName(" + column + ")");
    try
    {
      String result = resultSetMetaData.getCatalogName(column);
      if (data.trace >= 5)
        Util.traceEnd(key, Util.toString(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public int getColumnType(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getColumnType(" + column + ")");
    try
    {
      int result = resultSetMetaData.getColumnType(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public String getColumnTypeName(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getColumnTypeName(" + column + ")");
    try
    {
      String result = resultSetMetaData.getColumnTypeName(column);
      if (data.trace >= 5)
        Util.traceEnd(key, Util.toString(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isReadOnly(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isReadOnly(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isReadOnly(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isWritable(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isWritable(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isWritable(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }



  public boolean isDefinitelyWritable(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " isDefinitelyWritable(" + column + ")");
    try
    {
      boolean result = resultSetMetaData.isDefinitelyWritable(column);
      if (data.trace >= 5)
        Util.traceEnd(key, String.valueOf(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }




  public String getColumnClassName(int column) throws SQLException
  {
    long key = 0L;
    if (data.trace >= 5)
      key = Util.traceBegin(prefix + " getColumnClassName(" + column + ")");
    try
    {
      String result = resultSetMetaData.getColumnClassName(column);
      if (data.trace >= 5)
        Util.traceEnd(key, Util.toString(result));
      return result;
    }
    catch (SQLException e)
    {
      if (data.trace >= 5)
        Util.traceEnd(key, e);
      throw e;
    }
  }


}
